<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/9/12
 * Time: 15:26
 */

namespace Admin\Controller;

use Admin\Service\MenuService;
use Common\Base\BaseController;
use Common\Util\CommonUtil;

class PageController extends BaseController
{
    private $menuService = null;
    function __construct()
    {
        parent::__construct();

        $this->menuService = new MenuService();

        if (session('admin_login_info') == null) {
            if (CommonUtil::isAjax()) {
                $this->ajaxReturnWrap(null, -999, '页面已过期');
            } else {
                $this->display('../Public/' . PUBLIC_MODULE . '/webapp/admin/login.html');
            }

            exit();
        }

    }

    public function login()
    {
        if (session('admin_login_info') != null) {
            $this->redirect('admin/page/index');
        } else {
            $this->display('../Public/' . PUBLIC_MODULE . '/webapp/admin/login.html');
        }
    }

    public function logout()
    {
        session('admin_login_info', null);
        $this->redirect('admin/page/login');
    }

    public function index()
    {

        $menu = $this->menuService->getUserMenu(session('admin_login_info')['id']);

        $this->assign('menus', $menu);
        $this->assign('account', session('admin_login_info')['account']);
        $this->display('../Public/' . PUBLIC_MODULE . '/webapp/admin/admin.html');
    }

    public function getPart($page)
    {
        $this->display('../Public/' . PUBLIC_MODULE . '/webapp/admin/' . $page);
    }

}
